<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="../css/mui.picker.min.css" />
		<link rel="stylesheet" href="../css/iconfont.css">
		<style>
			.mui-content-padded{margin:5px 0 0 0;}
			.mui-row-list span{float: left; line-height:33px; width:20%;}
			.mui-row-list select{float: left; line-height:14px; font-size:14px; margin-top:2px; margin-left: 5px;}
			.mui-btn-block{margin-bottom:0; padding:6px;}
			.mui-col-sm-12{ border-top: 1px solid #D1D1D1; width:100%; padding-top:5px; font-size:14px;}
			input[type="text"],input[type="number"]{height:26px; padding: 0;border-width: 0;border-bottom-width: 1px;margin-bottom:0;background:none;}
			form:before{ background: none !important; border: none !important;}
			input{border-width:0; text-align: right; font-size:14px; height: 26px;}
			.bottom_soild{border-bottom: 1px solid #DDDDDD; margin-right: 5px;}
			.submit{
				margin:0 auto 10px auto; 
				width:200px; 
				height:35px; 
				line-height: 35px; 
				background-color:#007AFF; 
				text-align: center; 
				color: #FFFFFF; 
				border-radius: 10px;
				margin-top: 10px;
			}
		</style>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">生活方式</h1>
		</header>
		<div class="mui-conten" style="margin-top:50px;">
			<ul class="mui-table-view">
				<div class="mui-col-sm-12 mui-col-xs-12">
					<li class="mui-table-view-cell">
						<a style="float: left; font-size: 14px; width: 160px; line-height: 26px;">体重</a>
						<div style="float:right; line-height: 26px;">Kg</div>
						<input id='kg' type="number" class="ui-alert bottom_soild" placeholder="请输入" style="width:50%; float: right;"/>
					</li>
				</div>
			</ul>
			<ul class="mui-table-view" style="margin-top: 5px;">
				<div class="mui-col-sm-12 mui-col-xs-12">
					<li class="mui-table-view-cell">
						<a style="float: left; font-size: 14px; width: 160px; line-height: 26px;">吸烟</a>
						<div style="float:right; line-height: 26px;">天</div>
						<input id='smokingday' type="number" class="ui-alert bottom_soild" placeholder="请输入" style="width:20%; float: right;"/>
						<div style="float:right; line-height: 26px;">只</div>
						<input id='smoking' type="number" class="ui-alert bottom_soild" placeholder="请输入" style="width:20%; float: right;"/>
					</li>
					<li class="mui-table-view-cell">
						<a id='demo2' data-options='{"type":"date"}' class="btn mui-navigate-right">
							<div style="padding: inherit; float: left; font-size: 14px; width: 130px; line-height: 26px; margin: -11px -15px;">戒烟时间</div>
							<input id='result4' class="ui-alert" placeholder="请选择" style="width:50%; text-align: right; float: right; padding-right: 15px;"/>
						</a>
					</li>
				</div>
			</ul>		
			<ul class="mui-table-view" style="margin-top: 5px;">	
				<div class="mui-col-sm-12 mui-col-xs-12">
					<li class="mui-table-view-cell">
						<a style="float: left; font-size: 14px; width: 160px; line-height: 26px;">饮酒</a>
						<div style="float:right; line-height: 26px;">天</div>
						<input id='drinkingday' type="number" class="ui-alert bottom_soild" placeholder="请输入" style="width:20%; float: right;"/>
						<div style="float:right; line-height: 26px;">两</div>
						<input id='drinking' type="number" class="ui-alert bottom_soild" placeholder="请输入" style="width:20%; float: right;"/>
					</li>
					<li class="mui-table-view-cell">
						<a id='demo3' data-options='{"type":"date"}' class="btn mui-navigate-right">
							<div style="padding: inherit; float: left; font-size: 14px; width: 130px; line-height: 26px; margin: -11px -15px;">戒酒时间</div>
							<input id='result5' class="ui-alert" placeholder="请选择" style="width:50%; text-align: right; float: right; padding-right: 15px;"/>
						</a>
					</li>
				</div>
			</ul>
			<div style="margin-left:0.9rem; line-height:35px;">运动情况</div>
			<ul class="mui-table-view">
				<div class="mui-row">
					<div class="mui-col-sm-12 mui-col-xs-12">
						<li class="mui-table-view-cell">
							<div style="float:right; width:120px;">
								<input id='movement' type="number" class="ui-alert bottom_soild" placeholder="请输入" style=" width: 50%; float:left;"/>
								<div style="float: right; font-size: 14px; line-height: 26px; text-align: left; width: 50px;">次/周</div>
							</div>
						</li>
						<li class="mui-table-view-cell">
							<div style="float:right; width:120px;">
								<input id='movement1' type="number" class="ui-alert bottom_soild"  placeholder="请输入" style="width: 50%; float:left;"/>
								<div style="float: right; font-size: 14px; line-height: 26px; text-align: left; width: 50px;">分钟/次</div>
							</div>
						</li>
					</div>
				</div>
			</ul>
			<ul class="mui-table-view" style="margin-top: 5px;">
				<div class="mui-col-sm-12 mui-col-xs-12">
					<li class="mui-table-view-cell">
						<a id='demo4' data-options='{"type":"date"}' class="btn mui-navigate-right">
							<div style="padding: inherit; float: left; font-size: 14px; width: 130px; line-height: 26px; margin: -11px -15px;">饮食</div>
							<input id='result6' class="ui-alert" placeholder="请选择" style="width:50%; text-align: right; float: right; padding-right: 15px;"/>
						</a>
					</li>
				</div>	
			</ul>
			<ul class="mui-table-view" style="margin-top: 5px;">
				<div class="mui-col-sm-12 mui-col-xs-12">
					<li class="mui-table-view-cell">
							<div style="padding: inherit; float: left; font-size: 14px; width: 130px; line-height: 26px; margin: -11px -15px;">心理调整</div>
							<input id='psy1' class="ui-alert bottom_soild" placeholder="请输入" style="width:25%; text-align: right; float: right; padding-right: 15px;"/>
							<div style="float:right; line-height: 26px;">/</div>
							<input id='psy' class="ui-alert bottom_soild" placeholder="请输入" style="width:25%; text-align: right; float: right; padding-right: 15px;"/>
						</a>
					</li>
				</div>	
			</ul>
			<ul class="mui-table-view" style="margin-top: 5px;">
				<div class="mui-col-sm-12 mui-col-xs-12">	
					<li class="mui-table-view-cell">
						<a id='demo5' data-options='{"type":"date"}' class="btn mui-navigate-right">
							<div style="padding: inherit; float: left; font-size: 14px; width: 130px; line-height: 26px; margin: -11px -15px;">遵医行为</div>
							<input  id='result7' class="ui-alert"  placeholder="请选择" style="width:50%; text-align: right; float: right; padding-right: 15px;"/>
						</a>
					</li>
				</div>
			</ul>
			<div onclick="submit()" class="submit" >保存</div>
		</div>
		<script src="../js/mui.js"></script>
		<script src="../js/mui.picker.min.js"></script>
		<script src="../js/jquery.min-1.11.1.js"></script>
		<script src="../js/request.js"></script>
		<script type="text/javascript">
			//获取变量
			var self = localStorage.getItem("name")
			console.log(self)
			var dataold = JSON.parse(self)
			var obj = dataold.obj
			var selfdata ="";
			var listdata ="";
			mui.plusReady(function(){
				var self = plus.webview.currentWebview()
					listdata = self.data;
					visitId = self.visitdata;
					selfdata = JSON.parse(listdata)
					console.log(selfdata.ehrId)
				var date1 = new Date();
				var year1=date1.getFullYear(); 
				var month1=date1.getMonth()+1;
				var day1=date1.getDate();
				var h1=date1.getHours();
				var m1=date1.getMinutes();
				var s1=date1.getSeconds();
					month1 =(month1<10 ? "0"+month1:month1); 
					day1 =(day1<10 ? "0"+day1:day1); 
					h1 =(h1<10 ? "0"+h1:h1); 
					m1 =(m1<10 ? "0"+m1:m1); 
					s1 =(s1<10 ? "0"+s1:s1);
					createDate = (year1.toString()+'-'+month1.toString()+'-'+day1.toString()+' '+h1.toString()+':'+m1.toString()+':'+s1.toString());
					modifyDate = (year1.toString()+'-'+month1.toString()+'-'+day1.toString()+' '+h1.toString()+':'+m1.toString()+':'+s1.toString());
					ehrId = selfdata.ehrId;
				if(self.second != ""){
					first = JSON.parse(self.first);
					second = JSON.parse(self.second);
					id = first.id;
					createUser = first.createUser;
					createDate = first.createDate;
					console.log(self.second);
					for(var i=0; i<second.length; i++){
						if(second[i].questionId == "89"){
							console.log("123")
							document.getElementById("kg").value = second[i].answer;
						}
						if(second[i].questionId == "36"){
							document.getElementById("smoking").value = second[i].answer;
						}
						if(second[i].questionId == "523"){
							document.getElementById("smokingday").value = second[i].answer;
						}
						if(second[i].questionId == "38"){
							document.getElementById("result4").value = second[i].answer;
						}
						if(second[i].questionId == "40"){
							document.getElementById("drinking").value = second[i].answer;
						}
						if(second[i].questionId == "524"){
							document.getElementById("drinkingday").value = second[i].answer;
						}
						if(second[i].questionId == "42"){
							document.getElementById("result5").value = second[i].answer;
						}
						if(second[i].questionId == "30"){
							document.getElementById("movement").value = second[i].answer;
						}
						if(second[i].questionId == "31"){
							document.getElementById("movement1").value = second[i].answer;
						}
						if(second[i].questionId == "34"){
							var rowsdiet=resultall.r1
							for(var j=0; j<rowsdiet.length; j++){
								if(second[i].answerId == rowsdiet[j].id){
								document.getElementById("result6").value = rowsdiet[j].text;
								}
							}
						}
						if(second[i].questionId == "311"){
							document.getElementById("psy").value = second[i].answer;
						}
						if(second[i].questionId == "525"){
							document.getElementById("psy1").value = second[i].answer;
						}
						if(second[i].questionId == "312"){
							var rowsComp=resultall.r2
							for(var j=0; j<rowsComp.length; j++){
								if(second[i].answerId == rowsComp[j].id){
								document.getElementById("result7").value = rowsComp[j].text;
								}
							}
						}
					}
				}
			})
			//赋值
			var resultall = {"r1":[{value:'0',id:'0',text:' '},{value:'0',id:'479',text:'合理'},{value:'1',id:'527',text:'基本合理'},{value:'2',id:'481',text:'不合理'}],
							"r2":[{value:'0',id:'0',text:' '},{value:'0',id:'238',text:'良好'},{value:'1',id:'239',text:'一般'},{value:'2',id:'240',text:'差'}]}
			var id = 0;
			var visitId= 0;
			var ehrId = "";
			var manageId = 0;
			var createUser = obj.id;
			var createDate = "";
			var updateUser = obj.id;
			var modifyDate = "";
			var upsmok = "";
			var updrink = "";
			var diet = "";
			var Comp = "";
			mui.init()
			(function($) {
				$.init();
				var result = $('#result')[0];
				var btns = $('.btn');
				btns.each(function(i, btn) {
					btn.addEventListener('tap', function() {
						var _self = this;
						if(_self.picker) {
							_self.picker.show(function (rs) {
								result.innerText = rs.text;
								_self.picker.dispose();
								_self.picker = null;
							});
						} else {
							if(i == 0){
								var optionsJson = this.getAttribute('data-options') || '{}';
								var options = JSON.parse(optionsJson);
								var id = this.getAttribute('id');
								_self.picker = new $.DtPicker(options);
								_self.picker.show(function(rs) {
									$('#result4')[0].value = rs.text;
									_self.picker.dispose();
									_self.picker = null;
								});
							}else if(i == 1){
								var optionsJson = this.getAttribute('data-options') || '{}';
								var options = JSON.parse(optionsJson);
								var id = this.getAttribute('id');
								_self.picker = new $.DtPicker(options);
								_self.picker.show(function(rs) {
									$('#result5')[0].value = rs.text;
									_self.picker.dispose();
									_self.picker = null;
								});
							}else if(i == 2){
								var picker = new mui.PopPicker();
								 picker.setData([{value:'0',id:'238',text:'合理'},{value:'1',id:'239',text:'一般合理'},{value:'2',id:'240',text:'不合理'}]);
								 picker.show(function (selectItems) {
									 $('#result6')[0].value = selectItems[0].text;
								  })
							}else if(i == 3){
								var picker = new mui.PopPicker();
								 picker.setData([{value:'0',id:'238',text:'良好'},{value:'1',id:'239',text:'一般'},{value:'2',id:'240',text:'差'}]);
								 picker.show(function (selectItems) {
									 $('#result7')[0].value = selectItems[0].text;
								  })
							}else{
								
							}
						}
						
					}, false);
				});
			})(mui);
			//提交
			function submit(){
				upsmok = $('#result4')[0].value;
				updrink = $('#result5')[0].value;
				var diet1 = $('#result6')[0].value;
				for(var re=0; re<resultall.r1.length; re++){
					if(diet1 == resultall.r1[re].text){
						diet = resultall.r1[re].id;
					}
				}	
				var Comp1 = $('#result7')[0].value;
				for(var re=0; re<resultall.r2.length; re++){
					if(Comp1 == resultall.r2[re].text){
						Comp = resultall.r2[re].id;
					}
				}
				var dataobj=[
					//体重
					{"ehrId":ehrId,
					"visitId":visitId,
					"questionId":"89",
					"answerId":"0",
					"answer":mui("#kg")[0].value,
					"createDate":createDate,
					"createUser":createUser,
					"updateUser":updateUser},
					//吸烟 支
					{"ehrId":ehrId,
					"visitId":visitId,
					"questionId":"36",
					"answerId":"0",
					"answer":mui("#smoking")[0].value,
					"createDate":createDate,
					"createUser":createUser,
					"updateUser":updateUser},
					//吸烟 天
					{"ehrId":ehrId,
					"visitId":visitId,
					"questionId":"523",
					"answerId":"0",
					"answer":mui("#smokingday")[0].value,
					"createDate":createDate,
					"createUser":createUser,
					"updateUser":updateUser},
					//戒烟 年月
					{"ehrId":ehrId,
					"visitId":visitId,
					"questionId":"38",
					"answerId":"0",
					"answer":upsmok,
					"createDate":createDate,
					"createUser":createUser,
					"updateUser":updateUser},
					//饮酒 两
					{"ehrId":ehrId,
					"visitId":visitId,
					"questionId":"40",
					"answerId":"0",
					"answer":mui("#drinking")[0].value,
					"createDate":createDate,
					"createUser":createUser,
					"updateUser":updateUser},
					//饮酒 天
					{"ehrId":ehrId,
					"visitId":visitId,
					"questionId":"524",
					"answerId":"0",
					"answer":mui("#drinkingday")[0].value,
					"createDate":createDate,
					"createUser":createUser,
					"updateUser":updateUser},
					//戒酒 年月
					{"ehrId":ehrId,
					"visitId":visitId,
					"questionId":"42",
					"answerId":"0",
					"answer":updrink,
					"createDate":createDate,
					"createUser":createUser,
					"updateUser":updateUser},
					//运动次/周
					{"ehrId":ehrId,
					"visitId":visitId,
					"questionId":"30",
					"answerId":"0",
					"answer":mui("#movement")[0].value,
					"createDate":createDate,
					"createUser":createUser,
					"updateUser":updateUser},
					//运动分钟/次
					{"ehrId":ehrId,
					"visitId":visitId,
					"questionId":"31",
					"answerId":"0",
					"answer":mui("#movement1")[0].value,
					"createDate":createDate,
					"createUser":createUser,
					"updateUser":updateUser},
					//饮食
					{"ehrId":ehrId,
					"visitId":visitId,
					"questionId":"34",
					"answerId":diet,
					"answer":null,
					"createDate":createDate,
					"createUser":createUser,
					"updateUser":updateUser},
					//心理调整1
					{"ehrId":ehrId,
					"visitId":visitId,
					"questionId":"311",
					"answerId":"0",
					"answer":mui("#psy")[0].value,
					"createDate":createDate,
					"createUser":createUser,
					"updateUser":updateUser},
					//心理调整2
					{"ehrId":ehrId,
					"visitId":visitId,
					"questionId":"525",
					"answerId":"0",
					"answer":mui("#psy1")[0].value,
					"createDate":createDate,
					"createUser":createUser,
					"updateUser":updateUser},
					//遵医行为
					{"ehrId":ehrId,
					"visitId":visitId,
					"questionId":"312",
					"answerId":Comp,
					"answer":null,
					"createDate":createDate,
					"createUser":createUser,
					"updateUser":updateUser}
				]
				$.ajax({
					type: 'post',
					url:getRequestUrl.url+"/mobile/ehr/OldsterVisitAnswer/addOrUpdate",
					data:JSON.stringify(dataobj),
					dataType:"json",
					contentType : 'application/json;charset=utf-8',
					success : function(data) {
						if(data.status==1){
							alert("提交成功")
							mui.openWindow({
								url: 'follow_up_add.html', 
								id:'follow_up_add',
								extras:{
									
								}
							});
						}else{
							alert(data.message);
						}
					},
					error:function(xhr,type,errorThrown){
						
					}
				})
			}
		</script>
	</body>
</html>